<template>
  <view class="patrol">
    <view class="top-container">
      <image src="/static/imgs/complete.png"/>
      <span>本次巡查任务已完成！</span>
    </view>
    <view class="body-container">
      <view>
        <span>任务编号</span>
        <span>{{form.inventory_code}}</span>
      </view>
      <view>
        <span>设备总数</span>
        <span>{{form.device_item}}</span>
      </view>
      <view>
        <span>扫描结果</span>
        <span>{{form.scan_item}}</span>
      </view>
      <view>
        <u-button type="primary" @click="handlerComplete">完成</u-button>
      </view>
    </view>
  </view>
</template>

<script setup>
import {ref, reactive, computed} from "vue";
import {onLoad} from "@dcloudio/uni-app";
import request from "@/api/request";

const form = ref({})

onLoad((options) => {
  const item = JSON.parse(options?.item ?? null);
  if (item) {
    form.value = item
  }
})

const handlerComplete = async ()=> {
  console.log(form.value)
  let params = {
    pageId: '13528002-df21-4a07-acc1-82eaa40805a3',
    methodName: 'doSaveTableData',
    saveTableDataRequest: {
      data: {
        insert: {},
        otherData: {
          fileAttachments: []
        },
        pageAuths: [],
        remove: {},
        removeWhere: {},
        savedInvoke: {},
        update: {
          assetinventorymstr: {
            id: form.value.id,
            inventory_status: 'COMPLETED'
          },
        },
        updateWhere: {}
      }
    }
  }
  try {
    const resp = await request.post('/api/module/Invoke', params)
    console.log(resp)
    if (resp.isSuccess) {
      uni.showToast({
        title: '操作成功',
        icon: 'none',
        complete: () => {
          uni.$emit('refresh-data')
          uni.switchTab({
            url: '/pages/stocktaking/stocktaking'
          })
        }
      })
    } else {
      uni.showToast({
        title: '操作失败',
        icon: 'none'
      })
    }
  }catch (e) {
    console.error(e)
  }
}

</script>

<style scoped lang="scss">
.patrol {
  height: calc(100vh - var(--window-top));
  width: 100%;
  background-color: white;

  .top-container {
    height: 400rpx;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;

    > image {
      height: 200rpx;
      width: 200rpx;
    }

    > span {
      padding-top: 20rpx;
      font-weight: bold;
      font-size: 1.2rem;
    }
  }

  .body-container {
    width: 100%;
    padding: 60rpx;
    display: flex;
    flex-direction: column;
    align-items: center;

    > view {
      display: flex;
      align-items: center;
      width: 100%;

      > span:first-child {
        padding: 10rpx;
        display: block;
        width: 120rpx;
        text-align: right;
        font-size: .9rem;
      }

      > span:last-child {
        width: 60%;
        font-size: .8rem;
        color: #8f8f94;
      }

      &:last-child {
        margin-top: 60rpx;
      }
    }
  }
}
</style>